// Copyright (c) 2009 Mike Haight, Andy Kipp
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#pragma once

#include "stdafx.h"

#include "Object.h"
#include "Engine.h"
#include "Frame.h"
#include "Xml.h"

namespace HandBanana { namespace Core
{
    using namespace HandBanana::Utilities::Xml;

    /// <summary>
    /// 
    /// </summary>
    class Texture : public Object, public IXmlSerializable
    {
    // Constructor
    public:
        /// <summary>
        /// Create a new instance of the Texture class
        /// <summary>
        Texture(const std::wstring& argName, int argWidth, int argHeight, int argFrameWidth, int argFrameHeight);


    // Destructor
    private:
        /// <summary>
        /// Cleans up outstanding references to allocated textures.
        /// </summary>
        virtual ~Texture(void);


    // Public Properties
    public:
        /// <summary>
        /// Gets the DirectX texture pointer.
        /// </summary>
        IUnknown* Texture::TexturePointer(void) const;

        /// <summary>
        /// Gets the name of the texture.
        /// </summary>
        std::wstring Name(void) const;

        /// <summary>
        /// Gets the height of the texture, in pixels.
        /// </summary>
        int Height(void) const;

        /// <summary>
        /// Gets the width of the texture, in pixels.
        /// </summary>
        int Width(void) const;

        /// <summary>
        /// Gets the height of each frame of the texture.
        /// </summary>
        int FrameHeight(void) const;

        /// <summary>
        /// Gets the width of each frame of the texture.
        /// </summary>
        int FrameWidth(void) const;


    // Public Methods
    public:
        /// <summary>
        /// 
        /// </summary>
        void AddReference(void);

        /// <summary>
        /// 
        /// </summary>
        void Release(void);

        /// <summary>
        /// Gets a numbered frame from the texture.
        /// </summary>
        Frame GetFrame(int argFrameId) const;


    // IXmlSerializable Methods
    public:
        /// <summary>
        /// 
        /// </summary>
        virtual void WriteXml(const XmlWriter& argWriter);

        /// <summary>
        /// 
        /// </summary>
        virtual void ReadXml(const XmlReader& argParser);


    // Private Data Members
    private:
        IUnknown*       mTexturePointer;

        std::wstring    mName;
        int             mWidth, mHeight, mFrameWidth, mFrameHeight;
        float           mFloatFrameWidth, mFloatFrameHeight;
        int             mFramesPerRow;

        int             mReferenceCount;

    };
} }